﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SCRUM.Core.DataProviders;
using SCRUM.Core.BusinessObjects;
using System.Collections.Specialized;

namespace SCRUM.Core.DAO
{
    /// <summary>
    /// Static access object for handling BLIs
    /// </summary>
    public static class DAOComment
    {

        /// <summary>
        /// Returns all threads for specific entity
        /// </summary>
        /// <param name="entityID">ID of entity</param>
        /// <param name="type">Type of entity, task, bli, userstory, ...</param>
        /// <returns>List of threads</returns>
        public static List<Thread> GetAllThreadsForEntity(int entityID, string type)
        {
            return ProviderFactory.Provider.GetAllThreadsForEntity(entityID, type); 
        }

        /// <summary>
        /// Gets Thread object asociated with specified ID
        /// </summary>
        /// <param name="ID">ID of thread</param>
        /// <returns>Thread object</returns>
        public static Thread GetThreadByID(int ID)
        {
            return ProviderFactory.Provider.GetThreadByID(ID);
        }

        /// <summary>
        /// Gets all comments for specific thread
        /// </summary>
        /// <param name="threadID">ID of thread</param>
        /// <returns>List of comments for specified thread</returns>
        public static List<Comment> GetAllCommentsForThread(int threadID)
        {
            return ProviderFactory.Provider.GetAllCommentsForThread(threadID);
        }

        /// <summary>
        /// Returns all subcomments for comment
        /// </summary>
        /// <param name="ID">Id of comment</param>
        /// <returns>List of sub comments</returns>
        public static List<Comment> GetSubCommentsForComment(int ID)
        {
            return ProviderFactory.Provider.GetSubCommentsForComment(ID);
        }

        /// <summary>
        /// Creates new thread for entity
        /// </summary>
        /// <param name="thread">Thread to insert</param>
        /// <returns>Created thread with id</returns>
        public static Thread CreateNewThread(Thread thread)
        {
            return ProviderFactory.Provider.CreateNewThread(thread);
        }

        /// <summary>
        /// Creates new comment for entity
        /// </summary>
        /// <param name="comment">Comment to insert</param>
        /// <returns>Created comment with id</returns>
        public static Comment CreateNewComment(Comment comment, int inComment)
        {
            return ProviderFactory.Provider.CreateNewComment(comment, inComment);
        }

        /// <summary>
        /// Updates thread
        /// </summary>
        /// <param name="thread">Thread to update</param>
        public static void UpdateThread(Thread thread)
        {
            ProviderFactory.Provider.UpdateThread(thread);
        }

        /// <summary>
        /// Deletes thread
        /// </summary>
        /// <param name="thread">Thread to delete</param>
        public static void DeleteThread(Thread thread)
        {
            ProviderFactory.Provider.DeleteThread(thread.ID);
        }

        /// <summary>
        /// Updates comment
        /// </summary>
        /// <param name="comment">Comment to update</param>
        /// <param name="inComment">Parent comment</param>
        public static void UpdateComment(Comment comment, int inComment)
        {
            ProviderFactory.Provider.UpdateComment(comment, inComment);
        }

        /// <summary>
        /// Deletes comment
        /// </summary>
        /// <param name="comment">Comment to delete</param>
        public static void DeleteComment(Comment comment)
        {
            ProviderFactory.Provider.DeleteComment(comment.ID);
        }

        /// <summary>
        /// Gets Comment object asociated with specified ID
        /// </summary>
        /// <param name="ID">ID of Comment</param>
        /// <returns>Comment object</returns>
        public static Comment GetCommentByID(int ID)
        {
            return ProviderFactory.Provider.GetCommentByID(ID);
        }

        /// <summary>
        /// Gets all Comments object asociated with specified ID of entity
        /// </summary>
        /// <param name="ID">ID of Entity</param>
        /// <param name="type">Type of entity</param>
        /// <returns>All Comments </returns>
        public static IList<Comment> GetCommentsForEntity(int ID, string type)
        {
            return ProviderFactory.Provider.GetCommentsForEntity(ID, type);
        }

		/// <summary>
		/// Creates new comment.
		/// </summary>
		/// <param name="login">The login.</param>
		/// <param name="text">The text.</param>
		/// <param name="date">The date.</param>
		/// <param name="task">The task.</param>
		public static void CreateComment(string login, string text, DateTime date, Task task)
		{
			Thread thread = new Thread(0, DateTime.Now.ToShortDateString(), "Task", task.ID);
			thread = DAOComment.CreateNewThread(thread);
			Comment comm = new Comment(0, text, date, login, thread);
			Comment c = DAOComment.CreateNewComment(comm, -1);
		}
    }
}
